package com.dkd.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.dkd.contract.SupplyChannel;
import com.dkd.contract.SupplyContract;
import com.dkd.dao.TaskDetailsDao;
import com.dkd.entity.TaskDetailsEntity;
import com.dkd.service.TaskDetailsService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TaskDetailsServiceImpl extends ServiceImpl<TaskDetailsDao,TaskDetailsEntity> implements TaskDetailsService{
    @Override
    public List<TaskDetailsEntity> getByTaskId(long taskId) {

        QueryWrapper<TaskDetailsEntity> qw = new QueryWrapper<>();
        qw.lambda()
                .eq(TaskDetailsEntity::getTaskId,taskId);

        return this.list(qw);
    }

    @Override
    public SupplyContract buildSupplyContract(String innerCode,List<TaskDetailsEntity> details) {
        //2.构建协议内容
        SupplyContract supplyContract = new SupplyContract();
        supplyContract.setInnerCode(innerCode);//售货机编号
        List<SupplyChannel> supplyChannels = Lists.newArrayList();//补货数据
        //从工单明细表提取数据加到补货数据中
        details.forEach(d->{
            SupplyChannel channel = new SupplyChannel();
            channel.setChannelId(d.getChannelCode());//货道编号
            channel.setCapacity(d.getExpectCapacity());//补货数量
            supplyChannels.add(channel);
        });
        supplyContract.setSupplyData(supplyChannels);
        return supplyContract;
    }
}
